package com.example.demo.mapper;

import com.example.demo.mapper.entity.Student;
import com.example.demo.mapper.entity.StudentCertification;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * @author Lucy
 * @create 2024-01-30 22:09
 */
@Mapper
@Repository
public interface StudentCertificationMapper {
    @Select("SELECT * FROM student WHERE id = #{id}")
    Student selectStudentById(int id);

    @Insert("INSERT INTO student_certification(state, student_number,admission_notice,id_card_face,id_card_national,bareheaded_photo,disapprove_reason)" +
            "   VALUES( #{state}, #{studentNumber}, #{admissionNotice}, #{idCardFace}, #{idCardNational},#{bareheadedPhoto},#{disapproveReason})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertCertification(StudentCertification student);

    @Select("SELECT COUNT(*)" +
            "FROM student_certification " +
            "WHERE student_number = #{studentNumber};")
    int selectByNumber(String studentNumber);

    @Update("UPDATE student_certification "+
            "SET id_card_face = #{idCardFace} "+
            "WHERE student_number = #{studentNumber} ")
    void placeIdCardFace(StudentCertification cardFace);

    @Update("UPDATE student_certification "+
            "SET id_card_national = #{idCardNational} "+
            "WHERE student_number = #{studentNumber} ")
    void placeIdCardNational(StudentCertification national);

    @Update("UPDATE student_certification "+
            "SET admission_notice = #{admissionNotice} "+
            "WHERE student_number = #{studentNumber} ")
    void placeAdmissionNotice(StudentCertification admission);

    @Update("UPDATE student_certification "+
            "SET bareheaded_photo = #{bareheadedPhoto} "+
            "WHERE student_number = #{studentNumber} ")
    void placeBareheadedPhoto(StudentCertification bareheaded);

    @Select("SELECT COUNT(*) " +
            "FROM student " +
            "WHERE id = phone = #{phone};")
    int selectPhoneCount(String phone);
    @Select("SELECT COUNT(*) " +
            "FROM student " +
            "WHERE id = email = #{email};")
    int selectEmailCount(String email);
    @Update("UPDATE student "+
            "SET state = #{state} "+
            "WHERE id = #{id} ")
    int updateStudentState(Student currentStudent);

    @Update("UPDATE student "+
            "SET bareheaded_photo = #{bareheadedPhoto} "+
            "WHERE number = #{number} ")
    void updateBareheadedPhoto(Student currentStudent);

    @Update("UPDATE student "+
            "SET password = NULL,"+
            "phone = NULL, "+
            "email = NULL, "+
            "bareheaded_photo = NULL "+
            "WHERE id = #{id} ")
    int updateStudentNull(Student currentStudent);
    @Delete("DELETE FROM student_certification "+
            "WHERE student_number = #{studentNumber} ")
    int deleteCertification(Student currentStudent);
    @Update("UPDATE student "+
            "SET phone = #{phone}"+
            "WHERE id = #{id} ")
    int updateStudentPhone(Student currentStudent);
    @Update("UPDATE student "+
            "SET email = #{email} "+
            "WHERE id = #{id} ")
    int updateStudentEmail(Student currentStudent);
}
